//
//  HHInitAndEnumSample.swift
//  HHSwiftuiPractice
//
//  Created by YL-Hong on 2023/9/28.
//Init 初始化
//Enum 枚举

import SwiftUI

enum Fruit:String {
    case Apple = "Apple"
    case Grape = "Grape"
}

struct HHInitAndEnumSample: View {
    let background: Color
    let count: Int
    let fruitName: String
    
    init(fruit: Fruit, count: Int) {
        self.count = count
        if fruit == .Apple {
            self.background = Color.red
            self.fruitName = fruit.rawValue
            
        }else{
            self.background = Color.purple
            self.fruitName = fruit.rawValue
        }
//        self.background = background
//        self.count = count
//        self.fruitName = fruitName
    }
    
    var body: some View {
        VStack(spacing: 10) {
                   Text("\(count)")
                       .font(.largeTitle)
                       .underline()
                       .foregroundColor(Color.white)
                       
                   
                   Text("\(fruitName)")
                       .font(.headline)
                       .foregroundColor(Color.white)
               }
               .frame(width: 150, height: 150)
               .background(background)
               .cornerRadius(8)
    }
}

struct HHInitAndEnumSample_Previews: PreviewProvider {
    static var previews: some View {
        
        HStack{
            HHInitAndEnumSample(fruit: .Apple, count: 10)
            HHInitAndEnumSample(fruit: .Grape, count: 88)
        }
    }
}
